=========================================================================== BBS: The Abacus * HST/DS * Potterville MI Date: 02-12-93 (10:18) Number: 141 From: TOM BRADY Refer#: NONE To: RUSTY GORDON Recvd: NO Subj: Limiting The Length Of(1) Conf: (35) Quick Basi --------------------------------------------------------------------------- On 02-07-93 RUSTY GORDON wrote to ALL... RG> I understand how to limit the size of a string using RG> DIM variable$ as string * 15 etc... but how do I put a limit to the RG> number of characters the user can enter as in the sample below: RG> Below is some code I picked up recently, which I think will answer your needs. I can't remember where I got it, probably this echo, and I apologize for the creator's name being absent. It was posted apparently in response to a question just like yours (see the first paragraph). -----------------------------CUT HERE--------------------------------- ' In QBasic, how can you limit the amount that the cursor can travel in an ' INPUT statement? In other words, In an Input statement, how can I make the ' cursor not travel past a selected amount of spaces even if the user presses ' the space bar after the limit has been reached? ' I have noticed that if you keep the space bar pressed during an INPUT ' statement, it'll keep going forward and down the next line and the next ' till about 3 or 4 lines. Then it'll stop. ' What you have to do is to not use INPUT but build yourself an input ' routine which takes each character as it is entered and appends it to ' the end of a string which it builds as characters are entered. Then, ' you can (with each subsequent entry) check the length of the input ' string (the one you're building) and just not allow further input when ' the maximum field length has been met. ' Here's an input routine which was posted a while back by Margaret ' Romao. ' The VAL function may be used to convert the variable Inp$ to a numeric ' value. Sorry about the GOTO's. DECLARE SUB Parser (Inp$, Prompt$, Row%, Col%, Length%, Fore%, Back%) ' A little sample code to show how to call the procedure SCREEN 9 DEFINT A-Z COLOR 15, 1: CLS Parser Inp$, "Enter some text: ", 4, 4, 8, 15, 1 LOCATE 6, 4: PRINT "You entered: "; Inp$ DEFSNG A-Z SUB Parser (Inp$, Prompt$, Row%, Col%, Length%, Fore%, Back%) CPos% = LEN(Inp$) InpLength% = LEN(Inp$) COLOR Fore%, Back% LOCATE Row%, Col%, 1, 10, 11: PRINT Prompt$; GN1: DO: InKy$ = INKEY$: LOOP UNTIL LEN(InKy$) IF LEN(InKy$) = 1 THEN SELECT CASE ASC(InKy$) CASE 32 TO 126 ' std. alphanumeric keys IF InpLength% < Length% THEN temp1$ = LEFT$(Inp$, CPos%) temp2$ = RIGHT$(Inp$, InpLength% - CPos%) Inp$ = temp1$ + InKy$ + temp2$ InpLength% = InpLength% + 1 CPos% = CPos% + 1 LOCATE Row%, (Col% + LEN(Prompt$)) PRINT Inp$ LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% GOTO GN1 END IF CASE 8 'Backspace key IF InpLength% > 0 AND CPos% > 0 THEN temp1$ = LEFT$(Inp$, CPos% - 1) temp2$ = RIGHT$(Inp$, InpLength% - CPos%) Inp$ = temp1$ + temp2$ InpLength% = InpLength% - 1 CPos% = CPos% - 1 LOCATE Row%, (Col% + LEN(Prompt$)) PRINT Inp$ + CHR$(32) LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% END IF CASE 13 ' GOTO GNE CASE ELSE SOUND 400, 13 GOTO GN1 END SELECT ELSE InKy$ = (RIGHT$(InKy$, 1)) SELECT CASE ASC(InKy$) CASE 75 'right arrow IF CPos% > 0 THEN CPos% = CPos% - 1 LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% GOTO GN1 --==<<< Continued next message >>>==-- --- RBBSMail v18.2 * Origin: Newark Connection RBBS - Newark, OH (614)366-6588 (1:226/1240.0) SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1 SEEN-BY: 153/752 154/40 77 157/2 159/100 125 430 950 203/23 209/209 280/1 SEEN-BY: 390/1 396/1 15 397/2 2230/100 3603/20